package com.ywk.json.core.impl;


import com.ywk.json.core.IOutPut;
import com.ywk.json.entity.User;
import com.ywk.json.entity.User3;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zbh
 * @date 2022/3/9 14:07
 */
public class OutPutHandler3 implements IOutPut {

    @Override
    public List<User3> outPut(List contentList) {
        List<User3> user3List=new ArrayList<>();
        for (Object item : contentList) {
            User user=(User)item;
            User3 user3 = new User3();
            BeanUtils.copyProperties(user,user3);
            String pid=user.getPid();
            user3List.add(user3);
            for (User3 u3 : user3List) {
                if (u3.getId().equals(pid)) {
                    List<User> childList = u3.getUserList();
                    if (childList==null) {
                        childList=new ArrayList<>();
                        u3.setUserList(childList);
                    }
                    childList.add(user);

                }
            }
        }
        System.out.println("===============user3List=================");
        user3List.forEach(System.out::println);
        return user3List;
    }

}
